<html>
<head><meta charset="utf-8"><title>New lint for deref&#x27;ing a NULL pointer · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/New.20lint.20for.20deref&#x27;ing.20a.20NULL.20pointer.html">New lint for deref&#x27;ing a NULL pointer</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233886045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/New%20lint%20for%20deref%27ing%20a%20NULL%20pointer/near/233886045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/New.20lint.20for.20deref&#x27;ing.20a.20NULL.20pointer.html#233886045">(Apr 09 2021 at 20:31)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/83948">https://github.com/rust-lang/rust/pull/83948</a> implements a new lint against deref'ing NULL pointers (because <a href="https://grep.app/search?q=!%20offset_%3Fof&amp;regexp=true&amp;filter[lang][0]=Rust">it seems like people actually do that</a>). as far as I am concerned this is ready (r=me). Is any further process needed because this is a new lint?</p>



<a name="233892296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/New%20lint%20for%20deref%27ing%20a%20NULL%20pointer/near/233892296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/New.20lint.20for.20deref&#x27;ing.20a.20NULL.20pointer.html#233892296">(Apr 09 2021 at 21:12)</a>:</h4>
<p>I think usually new lints see feedback from t-lang? I don't know what the process is for that though</p>



<a name="233920127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/New%20lint%20for%20deref%27ing%20a%20NULL%20pointer/near/233920127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/New.20lint.20for.20deref&#x27;ing.20a.20NULL.20pointer.html#233920127">(Apr 10 2021 at 03:02)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span> from me, FWIW -- linting on UB seems like an obvious good.</p>
<p>Hmm, it applying even in a place expression is interesting.  I guess it has to because <code>ptr::addr_of!( (*foo).bar )</code> would be a <code>GEP inbounds</code>, and that would be UB on a null pointer.</p>



<a name="233937360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/New%20lint%20for%20deref%27ing%20a%20NULL%20pointer/near/233937360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/New.20lint.20for.20deref&#x27;ing.20a.20NULL.20pointer.html#233937360">(Apr 10 2021 at 08:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/131828-t-compiler/topic/New.20lint.20for.20deref'ing.20a.20NULL.20pointer/near/233920127">said</a>:</p>
<blockquote>
<p>Hmm, it applying even in a place expression is interesting.  I guess it has to because <code>ptr::addr_of!( (*foo).bar )</code> would be a <code>GEP inbounds</code>, and that would be UB on a null pointer.</p>
</blockquote>
<p>yes. this simply reflects the current wording in <a href="https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html">https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html</a> (also see <a href="https://github.com/rust-lang/reference/pull/1000">https://github.com/rust-lang/reference/pull/1000</a> ).</p>



<a name="233937438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/New%20lint%20for%20deref%27ing%20a%20NULL%20pointer/near/233937438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/New.20lint.20for.20deref&#x27;ing.20a.20NULL.20pointer.html#233937438">(Apr 10 2021 at 08:14)</a>:</h4>
<p>we might want to relax those rules in the future, but <code>ptr::addr_of!( (*NULL).bar )</code> is actual UB under our current LLVM compilation scheme, so this is not entirely theoretical (though I don't know if and how LLVM would use this to cause undesired compilation results)</p>



<a name="237725878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/New%20lint%20for%20deref%27ing%20a%20NULL%20pointer/near/237725878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/New.20lint.20for.20deref&#x27;ing.20a.20NULL.20pointer.html#237725878">(May 06 2021 at 20:48)</a>:</h4>
<p>I was forwarded here from <a href="#narrow/stream/122651-general/topic/bindgen.20failure.20with.20latest.20nightly">https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/bindgen.20failure.20with.20latest.20nightly</a> , I think this new lint broke bindgen</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>